﻿using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;

namespace DocX_WordDemo
{
    public static class Conversion
    {
        public static void ConvertToRtf(string fileName, string outputFileName)
        {
            Document doc = new Document(fileName);
            doc.SaveToFile(outputFileName, FileFormat.Rtf);
        }

        public static void ConvertToPdf(string fileName, string outputFileName)
        {
            Document doc = new Document(fileName);
            doc.SaveToFile(outputFileName, FileFormat.PDF);
        }

        public static void ConvertToImage(string fileName, string outputFileName)
        {
            Document doc = new Document(fileName);
            Image[] imgs = doc.SaveToImages(ImageType.Bitmap);
            for (int i = 0; i < imgs.Length; i++)
            {
                imgs[i].Save(string.Format("{0}-{1}.png", outputFileName, i), ImageFormat.Png);
            }
        }

        public static void ConvertToTxt(string fileName, string outputfileName)
        {
            Document doc = new Document(fileName);
            doc.SaveToTxt(outputfileName, Encoding.Default);
        }

        public static void ConvertToDoc(string fileName, string outputFileName)
        {
            Document doc = new Document(fileName);
            doc.SaveToFile(outputFileName, FileFormat.Doc);
        }

    }
}
